const Response = require("../../class/Response");

// 更新在线玩家信息
WSC.get('/bds/onlineInfo', (wsclient, req, res)=>{
    WSC.client.onlineClientsInfo = req.data.onlineClientsInfo;
    WSC.client.onlinePlayersInfo = req.data.onlinePlayersInfo;
    WSC.client.info = req.data.onlineClientsInfo[req.header.source_id.toString()];

    // 虚拟玩家列表
    if (CONF.CONFIG.get('PersonalConfig') && CONF.CONFIG.get('PersonalConfig')['EnableFakeList']){
        GMLIB_MC.removeAllFakeLists();
        for (let clientId in WSC.client.onlineClientsInfo){
            let bdsInfo = WSC.client.onlineClientsInfo[clientId];
            if (bdsInfo.userType != 'bds'){continue;}
            if (bdsInfo.bds.uuid == CONF.CONFIG.get('Websocket')['BDSUuid']){continue;}
            for (playerInfo of Object.values(bdsInfo.onlinePlayers)){
                GMLIB_MC.addFakeList(playerInfo.realName, playerInfo.xuid);
            }
        }
    }
});

// 服务-获取本服务器额外信息
WSC.get('/bds/getThisBdsInfo', async (thisClient, req, res)=>{
    thisClient.sendJson(Response.replyTo(req)
        .setUrl('/bds/getThisBdsInfo/result')
        .setData({
            bds: {
                maxPlayersNum: GMLIB_MC.getMaxPlayers(),
                averageTps: GMLIB_MC.getServerAverageTps(),
                mspt: GMLIB_MC.getServerMspt(),
            }
        })
    );
});

